import {forEach} from "@angular/router/src/utils/collection";
import {IModel} from "./IModel";
/**
 * Created by ybjaa on 2017/4/28.
 */
export class Menu implements IModel{

    public ID:number;
    public parentID:number;

    protected menuName:string="";
    public set MenuName(value:string)
    {
        let newValue=value;
        //if(newValue&&newValue.includes("\"")) newValue=value.replace("\"","'");
        this.menuName=encodeURIComponent(newValue);
    }

    public get MenuName():string
    {
        return decodeURIComponent(this.menuName);
    }


    protected menuURL:string="";

    public set MenuURL(value:string)
    {
        this.menuURL=encodeURIComponent(value);
    }

    public get MenuURL():string
    {
        return decodeURIComponent(this.menuURL);
    }

    public nextID:number;
    public isDelete:boolean;
    public isWrite:boolean;
    public children:Menu[]=[];

    public clone():Menu
    {
        let menu=new Menu();

        menu.ID=this.ID;
        menu.parentID=this.parentID;
        menu.menuName=this.menuName;
        menu.menuURL=this.menuURL;
        menu.nextID=this.nextID;
        menu.isDelete=this.isDelete;
        menu.isWrite=this.isWrite;
        menu.children=this.children;
        return menu;
    }



    public copyFrom(menu:Menu):Menu
    {
        this.ID=menu.ID;
        this.parentID=menu.parentID;
        this.menuName=menu.menuName;
        this.menuURL=menu.menuURL;
        this.nextID=menu.nextID;
        this.isDelete=menu.isDelete;
        this.isWrite=menu.isWrite;
        this.children=menu.children&&menu.children.map((v)=>v.clone&&v.clone()||new Menu().copyFrom(v))||null;

        return this;
    }

}